<?php
class WebsiteAddress {
    private $protocol;
    private $host;
    private $port;
    private $path;
    private $directory;
    
    public function __toString() {
        if (!$this->port) {
            $port = '';
        }
        elseif (($this->port == 80 && $this->protocol == 'http') ||
            ($this->port == 443 && $this->protocol == 'https')) {
            $port = '';
        }
        else {
            $port = ':'.$this->port;
        }
        
        return $this->protocol . '://' . $this->host . $port . $this->path;
    }
    
    public function getProtocol() {
        return $this->protocol;
    }

    public function setProtocol($protocol) {
        $this->protocol = $protocol;
    }

    public function getHost() {
        return $this->host;
    }

    public function setHost($host) {
        $this->host = $host;
    }

    public function getPort() {
        return $this->port;
    }

    public function setPort($port) {
        $this->port = (int) $port;
    }

    public function getPath() {
        return $this->path;
    }

    public function setPath($path) {
        $this->path = rtrim($path, '/');
    }
    
    public function getDirectory() {
        return $this->directory;
    }

    public function setDirectory($directory) {
        $this->directory = rtrim($directory, '/');
    }
}
